package com.rabbit2020.config;

import com.rabbitmq.client.Channel;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Date;

/**
 * 作者: LCG
 * 日期: 2020/2/27 23:26
 * 描述:
 */
@Component
@RabbitListener(queues = {"SI-XIN-QUEUE"})
public class ChuLiMessage {

    @Autowired
    private RabbitTemplate rabbitTemplate;


    @RabbitHandler
    public void chuLi(Object object, Message message,Channel channel) throws IOException {

        String format = DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss");
        System.out.println(message+"-------8------->"+format);

        channel.basicNack(message.getMessageProperties().getDeliveryTag(),false,true);

        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }
}
